// pages/index/ranking/countryCheckInfo/countryCheckInfo.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        loading: true,
        loadingAll: false,
        uid: '',
        countryArr: [],
        sceneImageArr: [],
        description: [],
    },
    //图片预览
    previewImgTap(e) {
        this.setData({
            sceneImageArr: e.currentTarget.dataset.srcarr,
            description: e.currentTarget.dataset.descarr,
        })
        //hideBottom隐藏图片预览的删除按钮
        wx: wx.navigateTo({
            url: `../../../checkIn/imgPreview/imgPreview?hideBottom=${true}&current=0`,
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        wx.setNavigationBarTitle({
            title: '国家数·' + options.checkincountrynum + '（' + options.checkincountryname + '）'
        })
        this.setData({
            uid: options.uid
        })
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        this.getcountryList()
    },

    getcountryList() {
        let _that = this
        if (!_that.data.loadingAll) {
            _that.setData({
                loading: true,
                loadingAll: false,
            })
            wx.request({
                url: app.globalData.rootPath + `cjMap/getCheckinCountryList`,
                method: "GET",
                header: {
                    "content-type": "application/x-www-form-urlencoded"
                },
                data: {
                    authId: app.globalData.authId,
                    uid: _that.data.uid
                },
                success: function(res) {
                    if (res.data.status == 0) {
                        for (let i = 0; i < res.data.data.length; i++) {
                            let time = res.data.data[i].checkintime.slice(0, 4) + '/' + res.data.data[i].checkintime.slice(5, 7)
                            let timeDay = res.data.data[i].checkintime.slice(8, 10) ? '/' + res.data.data[i].checkintime.slice(8, 10) : ''
                            res.data.data[i].checkintime = time + timeDay
                            _that.data.countryArr.push(res.data.data[i])
                        }
                        _that.setData({
                            countryArr: _that.data.countryArr,
                            loading: false,
                            loadingAll: true,
                        })
                        console.log(_that.data.countryArr)
                    } else {
                        if (res.data.errmsg == "输入页码超出范围") {
                            _that.setData({
                                loadingAll: true,
                                loading: false
                            })
                        }
                    }
                }
            });
        }
    },
})